package com.sise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sise.entity.ProductType;
import com.sise.mapper.ProductTypeMapper;
import com.sise.service.IProductTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zj
 */
@Service
public class ProductTypeServiceImpl extends ServiceImpl<ProductTypeMapper, ProductType> implements IProductTypeService {

    @Resource
    private ProductTypeMapper productTypeMapper;

    @Override
    public boolean save(ProductType productType) {
        int tag = productTypeMapper.insert(productType);
        return tag == 1;
    }

    @Override
    public boolean deleteById(Integer productTypeId) {
        int tag = productTypeMapper.deleteById(productTypeId);
        return tag == 1;
    }

    @Override
    public boolean deleteByIdList(List<Integer> productTypeIdList) {
        int tag = productTypeMapper.deleteBatchIds(productTypeIdList);
        return tag > 0;
    }

    @Override
    public boolean updateById(ProductType productType) {
        int tag = productTypeMapper.updateById(productType);
        return tag == 1;
    }

    @Override
    public ProductType findById(Integer productTypeId) {
        return productTypeMapper.selectById(productTypeId);
    }

    @Override
    public List<ProductType> findAll() {
        return productTypeMapper.selectList(null);
    }

    @Override
    public List<ProductType> findByStoreId(Integer storeId) {
        if (storeId.equals(-1)) {
            return productTypeMapper.selectList(null);
        } else {
            QueryWrapper<ProductType> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("store_id", storeId);
            return productTypeMapper.selectList(queryWrapper);
        }
    }
}
